package com.mini.framework.db.dbutil;

import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

public class MySqlPageQueryer implements PageQueryer {

	@Override
	public void pageQuery(String sql, QueryRunner runner, Class<?> clazz,
			int pageNo, int pageSize, Page page, Object... params) {
		StringBuilder sb = new StringBuilder();
		sb.append(sql);
		sb.append(" limit " + page.getStart() +"," + page.getEnd());
		try{
			List<? extends Object> list = (List<? extends Object>) runner.query(sb.toString(), new BeanListHandler(clazz),params);
			page.setResult(list);
		}catch(Exception e){
			e.printStackTrace();
		}
	}

}
